<template>
	<view>
		<view class="margin-bottom bg-white" v-for="(item,index) in list" :key="index">
			<view @click="onClick(item)" class="padding-sm">
				<view class="flex align-center ">
					<view class="flex-sub">
						<text v-if="item.status==1" class="cu-tag line-green margin-right-sm round">默认</text>
						{{item.phone}}
					</view>
					<view>{{item.name}}</view>
				</view>
				<view class="text-grey padding-tb-sm">{{item.address}}</view>
			</view>
			<view class="flex align-center solid-top text-lg">
				<view class="flex-sub text-center solid-right padding-tb">
					<navigator hover-class="none" :url="'/pages/user/address/edit?id=' + item.id">
						<view class="cuIcon-edit"></view>
					</navigator>
				</view>
				<view class="flex-sub text-center" @click="onDel(item.id)">
					<view class="cuIcon-delete"></view>
				</view>
			</view>
		</view>
		<view class="foot-but-h"></view>
		<view class="foot-but">
			<navigator class="cu-btn block bg-green lg" hover-class="none" url="/pages/user/address/edit">
				<text class="cuIcon-add"></text>新增收货地址
			</navigator>
		</view>
	</view>
</template>

<script>
	import AddressApi from "@/api/address"
	export default {
		data() {
			return {
				list: [],
			}
		},
		onLoad: function(option) {
			this.key = option.key
		},
		onShow() {
			this.getList();
		},
		methods: {
			getList() {
				AddressApi.list().then((res) => {
					this.list = res
				})
			},
			onDel(val) {
				AddressApi.del(val).then((res) => {
					this.getList()
				})
			},
			onClick(item) {
				if (this.key) {
					uni.setStorageSync(this.key, item);
					uni.navigateBack({
						delta: 1
					});
				}
			}
		}
	}
</script>

<style>

</style>
